 //食物类
 const ps = "absolute";
 class Food {

     constructor(option) {

         option = option instanceof Object ? option : {};

         //复制
         this.width = option.width || 20;
         this.height = option.height || 20;
         this.x = option.x || 0;
         this.y = option.y || 0;
         this.color = option.color || "green";

         //当前已经创建的food
         this.element = [];

     }


     render(map) {
             var ele = document.createElement("div");
             //获取随机位置
             this.x = Tools.getRandom(0, map.clientWidth / this.width - 1) * this.width;
             this.y = Tools.getRandom(0, map.clientHeight / this.height - 1) * this.height;
             ele.style.position = ps;
             ele.style.width = this.width + "px";
             ele.style.height = this.height + "px";
             ele.style.left = this.x + "px";
             ele.style.top = this.y + "px";
             ele.style.backgroundColor = this.color;
             //挂载food
             map.appendChild(ele);

             this.element.push(ele);
         }
         //移除当前食物
     remove(map, i) {
         //第一步从HTML 移除
         map.removeChild(this.element[i])
             //第二步从数组删除
         this.element.splice(i, 1);
     }

 }